In practice, the vector series in c ++ -- copy set to vector (do not confuse reserve and resize)
The stl algorithm has a copy function. We can easily write this Code:
#include
#include #include
using namespace std;int _tmain(int argc,
STD: Difference Between Reserve and resize of Vector1. Reserve: Allocate space, change capacity but not size2.Resize: Allocate space. Changing the capacity also changes the size.
If you know the vector size, resize it as an array without
There is a copy function in the STL algorithm. We can easily write this code:#include #include #include using namespace STD;int_tmain (intARGC, _tchar* argv[]) {Doubledarray[Ten]={1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9}; vectordouble>Vdouble (Ten);
Transfer from http://blog.sina.com.cn/s/blog_9f1c0931010180cy.htmlVectorsVector is part of the C + + Standard Template Library, which is a multifunctional template class and function library that can manipulate a variety of data structures and
For vector usage, the additional time consumed by copying data to prevent reallocate memory.
The following two combinations can be used to prevent reallocate.
1. Vector: resize () using array index
2. Vector: Reserve () Use push_back ().
Standard Library Vector type
Use the required header file:
# Include
Vector: Vector is a class template. It is not a data type. Vector is a data type.
I. Definition and initialization
Vector v1; // The default constructor v1 is empty.
Vector
Standard Template Library (STL) learn to explore the vector containerC + + VectorsVector is part of the C + + Standard Template Library, which is a multifunctional template class and function library that can manipulate a variety of data structures
Vector Common Methods
assign () assigning values to elements in vectors
void assign (Input_iterator start, Input_iterator end); //void assign (Size_type num, const type &VAL);
Reserve () sets the vector smallest element to hold the quantity function
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.